<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button onclick="start()">开始按钮</button>
    <button onclick="end()">结束按钮</button>
    <script>
        // setInterval(function(){},1000)
        var timer;
        var s = 1
        function start () {
            clearInterval(timer)
            timer = setInterval(function(){
                s++
                console.log(s)
            },1000)
        }

        function end () {
            s = 0
            clearInterval(timer)
        }
    </script>
</body>
</html>